#include"Date.h"


Date::Date(int year, int month, int day) 
{
	_year = year;
	_month = month;
	_day = day;
}

Date Date::operator=(const Date& d)
{
	if (this != &d)
	{
		_year = d._year;
		_month = d._month;
		_day = d._day;
	}

	return *this;
}

bool Date::operator==(const Date& x)
{
	return _year == x._year
		&& _month == x._month 
		&& _day == x._day;

}

bool Date::operator>(const Date& d)
{
	if (_year > d._year)
	{
		return true;
	}
	else if ((_year = d._year) && (_month > d._month))
	{
		return true;
	}
	else if ((_year = d._year) && (_month = d._month) && (_day > d._day))
	{
		return true;
	}
	return false;
}


bool Date::operator>=(const Date& d)
{
	return (*this > d) || (*this == d);
	//if (*this < d)
	//{
	//	return false;
	//}
	//return true;
}

bool Date::operator<(const Date& d)
{
	//if (_year < d._year)
	//	return true;
	//else if ((_year = d._year) && (_month < d._month))
	//	return true;
	//else if ((_year = d._year) && (_month = d._month) && (_day < d._day))
	//	return true;
	//return false;

	return !(*this >= d);
}

bool Date::operator<=(const Date& d)
{
	return !(*this > d);
	//if (*this > d)
	//{
	//	return false;
	//}
	//return true;
}


bool Date::operator!=(const Date& d)
{
	return !(*this == d);
}


int Date::GetMonthDay(int year, int month)
{
	static int a[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	if ((month == 2) && (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)))
	{
		return 29;
	}
	else
	{
		return a[month];
	}
}


Date& Date::operator+=(int day)
{
	_day += day;
	int num = GetMonthDay(_year, _month);
	while (_day > num)
	{
		_day -= num;
		++_month;
		if (_month == 13)
		{
			_month = 1;
			++_year;
		}
	}
	return *this;
}


Date Date::operator+(int day)
{
	Date tmp = *this;
	tmp += day;
	return tmp;
}


Date& Date::operator-=(int day)
{

}

